import type { Unit } from "@/pages/base/unit/entity";
import apiClient from "../../apiClient";

export interface PageListReq {
	unitCode: string;
	unitName: string;
	primaryFlag: number;
	changeRate: number;
	status: number;
	description: string;
	page: number;
	pageSize: number;
}

export interface PageListRes {
	total: number;
	records: Unit[];
}

const pageList = (data: PageListReq) => apiClient.post<PageListRes>({ url: "/base/unit/pageList", data });
const getInfo = (id: React.Key) => apiClient.get<Unit>({ url: `/base/unit/${id}` });
const add = (data: Unit) => apiClient.post<Unit>({ url: "/base/unit", data });
const update = (data: Unit) => apiClient.put<Unit>({ url: "/base/unit", data });
const remove = (ids: number[]) => apiClient.delete({ url: "/base/unit", params: { ids: ids.join(",") } });

// 获取下拉列表
const selectList = (): Promise<Unit[]> =>
	apiClient.get({
		url: "/base/unit/selectList",
	});

export default {
	pageList,
	selectList,
	getInfo,
	add,
	update,
	remove,
};
